<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>

<html class="app-ui">

<head>
    <!-- Meta -->
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>

    <!-- Document title -->
    <title>我的收获地址</title>

    <meta name="description" content="AppUI - Admin Dashboard Template & UI Framework"/>
    <meta name="author" content="rustheme"/>
    <meta name="robots" content="noindex, nofollow"/>

    <!-- Favicons -->
    <link rel="apple-touch-icon" href="${pageContext.request.contextPath}/assets/img/favicons/apple-touch-icon.png"/>
    <link rel="icon" href="${pageContext.request.contextPath}/assets/img/favicons/favicon.ico"/>


    <!-- AppUI CSS stylesheets -->
    <link rel="stylesheet" id="css-font-awesome" href="${pageContext.request.contextPath}/assets/css/font-awesome.css"/>
    <link rel="stylesheet" id="css-ionicons" href="${pageContext.request.contextPath}/assets/css/ionicons.css"/>
    <link rel="stylesheet" id="css-bootstrap" href="${pageContext.request.contextPath}/assets/css/bootstrap.css"/>
    <link rel="stylesheet" id="css-app" href="${pageContext.request.contextPath}/assets/css/app.css"/>
    <link rel="stylesheet" id="css-app-custom" href="${pageContext.request.contextPath}/assets/css/app-custom.css"/>
    <!-- End Stylesheets -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/js/layui/css/layui.css" media="all">
</head>

<body class="app-ui layout-has-drawer layout-has-fixed-header">
<div class="app-layout-canvas">
    <div class="app-layout-container">

        <!-- Drawer -->
        <aside class="app-layout-drawer">

            <!-- Drawer scroll area -->
            <div class="app-layout-drawer-scroll" style="margin-top: 50px;">
                <!-- Drawer logo -->
                <div id="logo" class="drawer-header"
                     style="text-align: center;margin: 0 auto;font-family: 华文楷体; padding-top: 20px;">
                    <span style="font-size: 34px;"><strong>我的账户</strong></span>
                </div>

                <!-- Drawer navigation -->
                <nav class="drawer-main">
                    <ul class="nav nav-drawer">
                        <li class="nav-item nav-drawer-header">
                            <hr color="#ccc">
                        </li>
                        <li class="nav-item">
                            <a href="${pageContext.request.contextPath}/jsp/MyAccount/MyMoneyRecord.jsp"><i class="ion-ios-speedometer-outline"></i>
                                <span>我的账户流水</span></a>
                        </li>
                        <li class="nav-item">
                            <a href="${pageContext.request.contextPath}/jsp/MyAccount/myInformation.jsp"><i class="ion-ios-monitor-outline"></i> 我的信息</a>
                        </li>
                        <li class="nav-item">
                            <a href="${pageContext.request.contextPath}/jsp/MyAccount/myOrder.jsp"><i class="ion-ios-monitor-outline"></i> 我的订单</a>
                        </li>
                        <li class="nav-item">
                            <a href="javascript:void(0)"><i class="ion-ios-monitor-outline"></i> <span style="font-size: 20px;">我的收获地址</span></a>
                        </li>
                        <li class="nav-item">
                            <a href="${pageContext.request.contextPath}/jsp/MyAccount/myOpinion.jsp"><i class="ion-ios-monitor-outline"></i> 我的评价</a>
                        </li>
                    </ul>
                </nav>
                <!-- End drawer navigation -->
            </div>
            <!-- End drawer scroll area -->
        </aside>
        <!-- End drawer -->

        <!-- Header -->
        <header class="app-layout-header">
            <nav class="navbar navbar-default">
                <div class="container">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                                data-target="#header-navbar-collapse"
                                aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <button class="pull-left hidden-lg hidden-md navbar-toggle" type="button" data-toggle="layout"
                                data-action="sidebar_toggle">
                            <span class="sr-only">Toggle drawer</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="${pageContext.request.contextPath}/jsp/home/frontend_home.jsp">
                            <img class="img-responsive"
                                 src="${pageContext.request.contextPath}/assets/img/logo/logo-frontend.png"
                                 title="强强组合商城" alt="AppUI"/>
                        </a>
                    </div>

                    <div class="collapse navbar-collapse" id="header-navbar-collapse">
                        <ul id="main-menu" class="nav navbar-nav navbar-left">
                            <li class="">
                                <a href="${pageContext.request.contextPath}/jsp/home/frontend_home.jsp">首页</a>
                            </li>
                            <li class="">
                                <a href="#" data-toggle="dropdown">关于我们</a>
                            </li>
                        </ul>
                        <!-- .navbar-left -->

                        <ul class="nav navbar-nav navbar-right navbar-toolbar hidden-sm hidden-xs">
                            <li class="active" id="business">
                                <a href="frontend_home.html">注册为商家</a>
                            </li>
                            <li class="active" id="deliver">
                                <a href="frontend_home.html">注册为配送员</a>
                            </li>
                            <li class="dropdown">
                                <a href="javascript:void(0)" data-toggle="dropdown"><i class="ion-ios-bell"></i> <span class="badge">3</span></a>
                                <ul class="dropdown-menu dropdown-menu-right">
                                    <li class="dropdown-header">消息</li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)"><span class="badge pull-right">3</span> 有无内鬼？ </a>
                                    </li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)"><span class="badge pull-right">1</span> 不过如此 </a>
                                    </li>
                                    <li class="divider"></li>
                                    <li class="dropdown-header">公告</li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)">登dua郎..</a>
                                    </li>
                                </ul>
                            </li>

                            <li class="dropdown dropdown-profile">
                                <a href="javascript:void(0)" data-toggle="dropdown">
                                    <span class="m-r-sm">${account.accName}<span class="caret"></span></span>
                                    <img class="img-avatar img-avatar-48" src="${pageContext.request.contextPath}/file/acc/${account.accImg == null?"000000011612245316757212.png":account.accImg}" alt="User profile pic" />
                                </a>
                                <ul class="dropdown-menu dropdown-menu-right">
                                    <li>
                                        <a href="${pageContext.request.contextPath}/jsp/MyAccount/MyMoneyRecord.jsp">个人账户</a>
                                    </li>
                                    <li>
                                        <a href="${pageContext.request.contextPath}/jsp/MyAccount/myBuyCart.jsp">我的购物车</a>
                                    </li>
                                    <li>
                                        <a href="#" id="logout">退出</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                        <!-- .navbar-right -->
                    </div>
                </div>
                <!-- .container-fluid -->
            </nav>
            <!-- .navbar-default -->
        </header>
        <!-- End header -->

        <main class="app-layout-content">

            <!-- Page Content -->
            <div class="container-fluid p-y-md">
                <!-- Checkable Table (.js-table-checkable class is initialized in App() -> uiHelperTableToolsCheckable()) -->
                <div class="card">
                    <div class="card-header">
                        <h4>收获地址</h4>
                    </div>
                    <div class="card-block">
                        <!-- If you put a checkbox in thead section, it will automatically toggle all tbody section checkboxes -->
                        <table class="table table-vcenter table-hover">
                            <thead>
                            <tr>
                                <th class="text-center w-5">
                                    <label class="css-input css-checkbox css-checkbox-default m-t-0 m-b-0">
                                        <span></span>
                                    </label>
                                </th>
                                <th>地址信息</th>
                                <th class="hidden-xs w-10">签收人</th>
                                <th class="hidden-xs w-10 text-center">电话</th>
                                <th class="hidden-xs w-15 text-center">修改</th>
                                <th class="hidden-xs w-15 text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody id="reAddressContent">
                            <tr>
                                <td class="text-center">
                                    <label class="css-input css-checkbox css-checkbox-default">
                                        <input type="radio" id="row_1" name="row_1" checked><span></span>
                                    </label>
                                </td>
                                <td>
                                    <p class="font-500 m-b-0"><code>默认</code>&nbsp;&nbsp;&nbsp;<span>江西省南昌市青山湖区</span></p>
                                </td>
                                <td class="hidden-xs">聂仔</td>
                                <td class="hidden-xs">
                                    <em class="text-muted">1814615465</em>
                                </td>
                                <td class="hidden-xs">
                                    <em class="text-muted">
                                        <button class="btn btn-app-orange" type="button" data-toggle="tooltip" title="修改"><span>修改</span></button>
                                    </em>
                                </td>
                                <td class="hidden-xs text-right">
                                    <em class="text-muted">
                                        <button class="btn btn-xs btn-app-light" style="display: none;" type="button" data-toggle="tooltip" title="设为默认"><span>设为默认</span></button>
                                        <button class="btn btn-xs btn-danger" type="button" data-toggle="tooltip" title="删除"><i class="ion-close"></i></button>
                                    </em>
                                </td>
                            </tr>
                            <tr>
                                <td class="text-center">
                                    <label class="css-input css-checkbox css-checkbox-default">
                                        <input type="radio" id="row_2" name="row_1"><span></span>
                                    </label>
                                </td>
                                <td>
                                    <p class="font-500 m-b-0"><code style="display: none;">默认</code>&nbsp;&nbsp;&nbsp;<span>广西壮族自治区贵港市港北区达开路</span></p>
                                </td>
                                <td class="hidden-xs">hzl</td>
                                <td class="hidden-xs">
                                    <em class="text-muted">312313</em>
                                </td>
                                <td class="hidden-xs">
                                    <em class="text-muted">
                                        <button class="btn btn-app-orange" type="button" data-toggle="tooltip" title="修改"><span>修改</span></button>
                                    </em>
                                </td>
                                <td class="hidden-xs text-right">
                                    <em class="text-muted">
                                        <button class="btn btn-xs btn btn-app-teal" style="height: 40px;" type="button" data-toggle="tooltip" title="设为默认"><span>设为默认</span></button>
                                        <button class="btn btn-xs btn-danger" style="margin-left: 10px;" type="button" data-toggle="tooltip" title="删除"><i class="ion-close"></i></button>
                                    </em>
                                </td>
                            </tr>
                            <tr>
                                <td class="text-center">
                                    <label class="css-input css-checkbox css-checkbox-default">
                                        <input type="radio" id="row_3" name="row_1"><span></span>
                                    </label>
                                </td>
                                <td>
                                    <p class="font-500 m-b-0"><code style="display: none;">默认</code>&nbsp;&nbsp;&nbsp;<span>华东交通大学理工学院8栋555</span></p>
                                </td>
                                <td class="hidden-xs">lzq</td>
                                <td class="hidden-xs">
                                    <em class="text-muted">121215421</em>
                                </td>
                                <td class="hidden-xs">
                                    <em class="text-muted">
                                        <button class="btn btn-app-orange" type="button" data-toggle="tooltip" title="修改"><span>修改</span></button>
                                    </em>
                                </td>
                                <td class="hidden-xs text-right">
                                    <em class="text-muted">
                                        <button class="btn btn-xs btn btn-app-teal" style="height: 40px;" type="button" data-toggle="tooltip" title="设为默认"><span>设为默认</span></button>
                                        <button class="btn btn-xs btn-danger" style="margin-left: 10px;" type="button" data-toggle="tooltip" title="删除"><i class="ion-close"></i></button>
                                    </em>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <div class="text-center">
                            <button class="btn btn-success" style="height: 50px;" type="button" data-toggle="tooltip" id="addReAddress"
                                    title="新增收获地址"><span>新增收获地址</span>
                            </button>
                        </div>
                    </div>
                    <!-- .card-block -->
                </div>
                <!-- .card -->
                <!-- End Checkable Table -->

            </div>
            <!-- .container-fluid -->
            <!-- End Page Content -->

        </main>
    </div>
    <!-- .app-layout-container -->
</div>

<!-- .app-layout-canvas -->

<!-- AppUI Core JS: jQuery, Bootstrap, slimScroll, scrollLock and App.js -->
<!-- AppUI Core JS: jQuery, Bootstrap, slimScroll, scrollLock and App.js -->
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.scrollLock.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.placeholder.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/app-custom.js"></script>

<!-- Page JS Plugins -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/bootstrap-colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/select2/select2.full.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/masked-inputs/jquery.maskedinput.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/dropzonejs/dropzone.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/jquery-tags-input/jquery.tagsinput.min.js"></script>
<div class="app-ui-mask-modal"></div>

<script src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
<script src="${pageContext.request.contextPath}/js/layui/layui.js"></script>

<script type="text/javascript">
    $(function (){
        var accId = ${account.accId};
        var ordId;
        getAllReaddress();//获取所有收获地址

        function getAllReaddress() {
            var url = "${pageContext.request.contextPath}/accountInfo/selectReceiveAddressByAccId";
            var param = {
                accId:accId
            };
            $.get(url,param,function (data) {
                if (data.code == 1001){
                    $("#reAddressContent").html("");
                    var content = "";
                    var reDeAddress ="";
                    for (var i = 0; i < data.receiveAddressList.length; i++) {
                        reDeAddress = data.receiveAddressList[i].reDefaultAddress == 1?"<code>默认</code>":"";
                        content += "<tr><td class='text-center'><label class='css-input css-checkbox css-checkbox-default'>";
                        content += "<span></span></label></td><td>";
                        content += "<p class='font-500 m-b-0'>"+reDeAddress+"&nbsp;&nbsp;&nbsp;<span>"+data.receiveAddressList[i].reAddress+"</span></p></td>";
                        content += "<td class='hidden-xs'>"+data.receiveAddressList[i].reLinkman+"</td><td class='hidden-xs'>";
                        content += "<em class='text-muted'>"+data.receiveAddressList[i].reTelephone+"</em></td><td class='hidden-xs text-center'><em class='text-muted'>";
                        content += "<button class='btn btn-app-orange editReAddress' type='button' data-toggle='tooltip' value='"+data.receiveAddressList[i].reAddressId+"' title='修改'><span>修改</span></button></em>";
                        content += "</td><td class='hidden-xs text-right'><em class='text-muted'>";
                        if (i != 0){
                            content += "<button class='btn btn-xs btn btn-app-teal editDefaultReAddress' value='"+data.receiveAddressList[i].reAddressId+"' style='height: 40px;' type='button' data-toggle='tooltip' title='设为默认'><span>设为默认</span></button>";
                            content += "<button class='btn btn-xs btn-danger deleteReAddress' style='margin-left: 10px;' value='"+data.receiveAddressList[i].reAddressId+"' type='button' data-toggle='tooltip' title='删除'><i class='ion-close'></i></button>";
                        }
                        content += "</em></td></tr>";
                    }
                    $("#reAddressContent").html(content);
                }
            });
        }
        /*  修改收获地址  */
        $("#reAddressContent").delegate(".editReAddress","click",function () {
            window.location.href = "${pageContext.request.contextPath}/jsp/MyAccount/add_address.jsp?reAddressId="+$(this).val()+"&isAddaddress="+128;
        });
        /*  新增收获地址  */
        $("#addReAddress").click(function () {
            window.location.href = "${pageContext.request.contextPath}/jsp/MyAccount/add_address.jsp?isAddaddress="+64;
        });
        /*  删除收获地址  */
        $("#reAddressContent").delegate(".deleteReAddress","click",function () {
            var url = "${pageContext.request.contextPath}/accountInfo/deleteMyReAddress";
            var param = {
                reAddressId:$(this).val(),
                _method:"delete"
            }
            $.post(url,param,function (data) {
                if (data.code == 1001){
                    alert("删除成功！");
                    getAllReaddress();
                }
            })
        });
        /*  设置为默认收获地址   */
        $("#reAddressContent").delegate(".editDefaultReAddress","click",function () {
            var url = "${pageContext.request.contextPath}/accountInfo/updateMyReAddressDefault";
            var param = {
                accId:accId,
                reAddressId:$(this).val(),
                _method:"put"
            }
            $.post(url,param,function (data) {
                if (data.code == 1001){
                    getAllReaddress();
                }
            })
        });

        /*动态显示首页头部*/
        var role = ${account.role};
        if(role == 2){
            $("#business").html("<a href='../business/UnFinishOrder.jsp'>商家后台</a>");
            $("#deliver").html("");
        }
        if(role == 3){
            $("#business").html("");
            $("#deliver").html("<a href='#'>配送员后台</a>");
        }
        /*退出登录*/
        $("#logout").click(function (event){
            event.preventDefault();
            var url = "/login/logoutShop";
            $.post(url,function (){
                window.location.href = "../../login.jsp";
            })
        })


    });

</script>

</body>

</html>
